import Vue from 'vue'
import Router from 'vue-router'
import Home from '../screens/Home.vue'
import global from 'util/global'
import conf from 'conf/index'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  routes: [{
      path: '/',
      name: '首页',
      component: Home
    },
    {
      path: '/jump',
      name: '跳转中',
      component: () => import('../screens/jump.vue')
    },
    {
      path: '/nearby',
      name: '全部校区',
      component: () => import('../screens/nearby.vue')
    },
    {
      path: '/location',
      name: '校区位置',
      component: () => import('../screens/locationMap.vue')
    },
    {
      path: '/course',
      name: '我的课程',
      component: () => import('../screens/myCourse.vue')
    },
    {
      path: '/schedule',
      name: '我的课表',
      component: () => import('../screens/schedule.vue')
    },
    {
      path: '/adjust-course',
      name: '调课',
      component: () => import('../screens/AdjustCourse.vue')
    },
    {
      path: '/select-lecture',
      name: '调课讲次',
      component: () => import('../screens/SelectLecture.vue')
    },
    {
      path: '/transferred-course',
      name: '调入班级',
      component: () => import('../screens/TransferredCourse.vue')
    },
    {
      path: '/Assessment',
      name: '学前评估',
      component: () => import('../screens/Assessment.vue')
    },
    {
      path: '/test-enter',
      name: '考前须知',
      component: () => import('../screens/TestEnter.vue')
    },
    {
      path: '/test',
      name: '测试',
      component: () => import('../screens/Test.vue')
    },
    {
      path: '/test-result',
      name: '测试结果',
      component: () => import('../screens/TestResult.vue')
    },
    {
      path: '/external-score',
      name: '输入成绩',
      component: () => import('../screens/ExternalScore.vue')
    },
    {
      path: '/jumpFeedback',
      name: '反馈中转页',
      component: () => import('../screens/jumpFeedback.vue')
    },
    {
      path: '/jumpReport',
      name: '测评中转页',
      component: () => import('../screens/jumpReport.vue')
    }
  ]
})
// 路由前置，用于兑换ticket
router.beforeEach((to, from, next) => {
  let accessToken = window.sessionStorage.getItem('accessToken') || ''
  let {ticket} = to.query
  if (accessToken || ticket) {
    next()
  } else {
    let loginWay = global.isWeixin() ? 'wx' : 'sms'
    window.location.href = `${conf.baseApiPath}/yyfn-api/cas/login?loginWay=${loginWay}&returnUrl=${window.location.origin}/jump?toUrl=${encodeURIComponent(to.fullPath)}`
  }
})
export default router